using System;
using System.Runtime;
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;




public class LoginNetHandler : Singleton< LoginNetHandler > 
{
	
	void Awake ()
	{
		if ( mInstance == null )
		{
			mInstance = this;
			initHandler();
		}
		
	}

	public void initHandler()
	{
		GameSocketManager.instance.regeditMsg( (int)GameNetMessage.MsgType._MSG_RECV_LOGIN_GAMESERVICE , onRecvLogin , typeof( GameNetMessage.RECV_MSG_LOGIN_GAMESERVICE ) );


	}

	
	public unsafe void sendLogin( string a , string p , int guest )
	{
		GameNetMessage.SEND_MSG_LOGIN_MAINSERVICE msg = new GameNetMessage.SEND_MSG_LOGIN_MAINSERVICE();
		msg.initNetHead();

		int alen = a.Length;
		int plen = p.Length;

		if ( alen >= GameDefine.MAX_NAME )
		{
			alen = GameDefine.MAX_NAME - 1;
		}
		if ( plen >= GameDefine.MAX_NAME )
		{
			plen = GameDefine.MAX_NAME - 1;
		}

		for ( int i = 0; i < alen ; i++ )
		{
			msg.Account[ i ] = (byte)a[ i ];
		}
		for ( int i = 0; i < plen ; i++ )
		{
			msg.PassWord[ i ] = (byte)p[ i ];
		}

		msg.Guest = 1;
		msg.Version = GameDefine.GAME_VERSION;

		GameSocketManager.instance.sendMsg( msg );
	}


	public void onRecvLogin( GameNetMessage.NetMsgInterface head )
	{
		GameNetMessage.RECV_MSG_LOGIN_GAMESERVICE msg = ( GameNetMessage.RECV_MSG_LOGIN_GAMESERVICE )head;

		if ( msg.Stage == 1 ) 
		{
		}
		
	
		LoginUIHandler.instance.enabelUI( true );

	}
	
	
}


